import 'dart:developer';
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:schoolassets/%E7%9B%98%E7%82%B9/%E7%9B%98%E7%82%B9%E8%AE%A1%E5%88%92%E8%AF%A6%E6%83%85/Inventory.dart';
import 'package:schoolassets/Tools%E5%B7%A5%E5%85%B7/ShowToast.dart';
import 'package:schoolassets/Tools%E5%B7%A5%E5%85%B7/requestUrl.dart';
class InventoryList extends StatefulWidget {
  const InventoryList({Key? key}) : super(key: key);

  @override
  State<InventoryList> createState() => _InventoryListState();
}

class _InventoryListState extends State<InventoryList> {
  var files = [];
  ///分组入库信息列表
  List<DataRow> KuMessage = [];
  @override
  void initState() {
    super.initState();
    Future.delayed(Duration.zero, () {
      // 获取盘点计划
      GetRfidPlan();
    });
    // 加载本地文件
    // LoadFile();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        iconTheme: IconThemeData(
          color: Colors.black, //修改颜色
        ),
        title: Text(
          "选择盘点任务",
          style: TextStyle(color: Colors.black),
        ),
        centerTitle: true,
        backgroundColor: Colors.white,
        elevation: 0,
        actions: [
          IconButton(onPressed: (){
            // 获取盘点计划
            GetRfidPlan();
          }, icon: Icon(Icons.refresh))
        ],
      ),
      body: Container(
      color: Colors.white,
        child: Column(
          children: [
            ///中间文字
            Container(
              padding: EdgeInsets.only(left: 15,right: 15,top: 15),
              alignment: Alignment.topLeft,
              child: Text("盘点计划单列表:",style: TextStyle(fontSize: 17,fontWeight: FontWeight.w600),),
            ),
            Expanded(
                child: ListView.builder(
                    itemCount: files.length,
                    itemBuilder: (context, index) {
                      return buildListViewItem(index);
                    }))
          ],
        ),
      ),
    );
  }

  // 文件列表样式
  Widget buildListViewItem(index) {
    return Column(
      children: <Widget>[
        Container(
          padding: EdgeInsets.all(10),
          decoration: BoxDecoration(
              border: Border(
                  bottom: BorderSide(width: 1, color: Color(0xfff2f2f2)))),
          child: ListTile(
            leading: Image.asset("Image/wenjian.png",width: 40,height: 40,),
            title: Container(
              alignment: Alignment.topLeft,
              child: Text(
                "${files[index]['Name']}",
                style: TextStyle(fontSize: 15),
              ),
            ),
            subtitle: Row(
              mainAxisAlignment: MainAxisAlignment.spaceBetween,
              children: [
              Text("计划盘点数：${files[index]['Count']}"),
              Text("实际盘点数：${files[index]['Count_OK']}")
            ],),
            contentPadding: EdgeInsets.all(5),
            onTap: () {
              print("盘点单号:${files[index]['ID']}");
              // 前往盘点页面
              Navigator.of(context).push(new MaterialPageRoute(builder: (_)=>Inventory(planID:files[index]['ID'])),).then((val){
                if(val=="reflash"){
                  GetRfidPlan();
                }

              });
            },
          ),
        )
      ],
    );
  }

// 获取盘点计划
  Future<void> GetRfidPlan() async {
    var ResponseData;
    ResponseData = await new requestUrl().CommenRequest(
        '/api/AppAssetInventory/GetList', 'post', {}, "拉取数据中...", context, true,"");
    if (ResponseData['code'] == 0) {
      files = ResponseData['data'];
      setState(() {});
    } else {
      ShowToast().MyToast(ResponseData['msg']);
    }
  }

}
